package com.controller;

import com.dto.Result;
import com.entity.BuildingInfo;
import com.service.BuildingInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/building")
public class BuildingController {
    
    @Autowired
    private BuildingInfoService buildingInfoService;
    
    /**
     * 创建楼栋信息
     * @param buildingInfo 楼栋信息
     * @return 结果
     */
    @PostMapping
    public void create(@RequestBody BuildingInfo buildingInfo) {
        buildingInfoService.create(buildingInfo);
    }
    
    /**
     * 删除楼栋信息
     * @param id 楼栋ID
     * @return 结果
     */
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        buildingInfoService.deleteById(id);

    }
    
    /**
     * 更新楼栋信息
     * @param buildingInfo 楼栋信息
     * @return 结果
     */
    @PutMapping
    public void update(@RequestBody BuildingInfo buildingInfo) {
        buildingInfoService.update(buildingInfo);
    }
    
    /**
     * 分页查询楼栋信息
     * @param pageNum 页码，默认为1
     * @param pageSize 每页大小，默认为10
     * @return 楼栋信息分页结果
     */
    @GetMapping
    public Page<BuildingInfo> findAll(@RequestParam(defaultValue = "1") int pageNum,
                          @RequestParam(defaultValue = "10") int pageSize) {
        return buildingInfoService.findAll(pageNum, pageSize);
    }
    
    /**
     * 根据ID查询楼栋信息详情
     * @param id 楼栋ID
     * @return 楼栋信息
     */
    @GetMapping("/{id}")
    public BuildingInfo findById(@PathVariable Integer id) {
        return buildingInfoService.findById(id);
    }
}